<?php
// DIC configuration
/** @var Pimple\Container $container */

$container = $app->getContainer();

$container['errorHandler'] = function ($c){
    return new \App\Exceptions\ErrorHandler($c['settings']['displayErrorDetails']);
};

//app Service Providers

$container->register(new \App\Services\Database\EloquentServiceProvider());
$container->register(new \App\Services\Auth\AuthServiceProvider());

$container['logger'] = function ($c){
    $settings    = $c->get('settings')['logger'];
    $logger      = new \Monolog\Logger($settings['name']);
    $logger_path = $settings['path'].date("Y-m-d").".log";
    $logger->pushProcessor(new Monolog\Processor\UidProcessor());
    $logger->pushHandler(new \Monolog\Handler\StreamHandler($logger_path, $settings['level']));

    return $logger;
};


$container['jwt'] = function ($c){
    $jwt_settings = $c->get('settings')['jwt'];
    return new \App\Middleware\JwtAuthMiddleware($jwt_settings);
};



$container['validator'] = function($c){
    \Respect\Validation\Validator::with('\\App\\Validation\\Rules');
    return new \App\Validation\Validator();
};

// Fractal
$container['fractal'] = function ($c) {
    $manager = new \League\Fractal\Manager();
    $manager->setSerializer(new \League\Fractal\Serializer\ArraySerializer());

    return $manager;
};



